package com.cictec.middleware.gps.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.cictec.middleware.commons.utils.ZoneUtils;
import com.cictec.middleware.core.entity.StandbyZone;
import com.cictec.middleware.gps.pojo.BusLineInfo;
import com.vividsolutions.jts.geom.Geometry;

/**
 * 线路信息-待发区service
 * @author ql
 *
 */
@Service
public class BusLineStandbyService {

	public static Logger logger = LoggerFactory.getLogger(BusLineStandbyService.class);

	public Map<String, Geometry> initLineStandbyGeometry(List<StandbyZone> standbyZones) {
		// TODO Auto-generated method stub
		Map<String, Geometry> map = new HashMap<String, Geometry>();
		for (StandbyZone standbyZone : standbyZones) {
			map.put(standbyZone.getLineType(), ZoneUtils.createPolygonGeometry(standbyZone.getPoints()));// 初始化生成围栏信息，方便后边不做重复生成操作
		}
		return map;
		
	}
	
	
	public StandbyZone getStandbyZoneByPosition(BusLineInfo busLineInfo, double lat, double lng) {
		for (StandbyZone standbyZone : busLineInfo.getStandbyZones()) {
			// 方法优化，这样不需要在每个点重复构件图形
			if(ZoneUtils.isInZoneFence(busLineInfo.getLineStandbyZonesGeometry().get(standbyZone.getLineType()), lat, lng)){
				return standbyZone;
			}
		}
		return null;
	}
	
}
